package com.loong.life.controller.backend;

import com.loong.common.mvc.BaseBackendController;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonInsert;
import com.loong.common.validator.group.CommonUpdate;
import com.loong.life.common.backend.param.AgentInformationParam;
import com.loong.life.common.backend.param.AgentQueryParam;
import com.loong.life.handler.AgentInformationHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 处理有关代理商信息请求的controller
 * @Author: 刘群
 * @Date: 2020/11/26 16:41
 */
@RestController
@RequestMapping("manage/life/agentInformation")
public class AgentInformationController extends BaseBackendController {

    @Resource
    private AgentInformationHandler agentHandler;

    /**
     * 新增代理商
     * @param param 代理商参数
     * @return 响应的结果
     */
    @PostMapping("save")
    public Result saveAgent(@Validated({CommonInsert.class}) AgentInformationParam param){
        param.setId(null);
        return handlerExecutor.execute(() -> agentHandler.saveAgent(param));
    }

    /**
     * 更新代理商
     * @param param 代理商参数
     * @return 响应的结果
     */
    @PostMapping("update")
    public Result updateAgent(@Validated({CommonUpdate.class}) AgentInformationParam param){
        return handlerExecutor.execute(() -> agentHandler.updateAgent(param));
    }

    /**
     * 批量删除代理商
     * @param idList 代理商id集合
     * @return 响应的结果
     */
    @PostMapping("batchDelete")
    public Result batchDeleteAgent(@RequestParam("idList") List<Long> idList){
        return handlerExecutor.execute(() -> agentHandler.batchDeleteAgent(idList));
    }

    /**
     * 分页查询代理商
     * @param param 查询参数
     * @return 响应的结果
     */
    @PostMapping("pageQuery/agentList")
    public Result pageQueryAgent(AgentQueryParam param){
        return handlerExecutor.execute(() -> agentHandler.pageQueryAgent(param));
    }
}
